package com.sikaryofficial.backend.controller.information;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.annotation.Repeat;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleOwnerListReq;
import com.sikaryofficial.backend.domain.dto.req.information.GetLikesListReq;
import com.sikaryofficial.backend.domain.dto.resp.information.ArticleGetLikesDTO;
import com.sikaryofficial.backend.manager.information.ArticleFrontEndManager;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import com.sikaryofficial.system.api.model.infomation.ArticleDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文章Controller
 *
 * @author qinjinyuan
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/article/owner")
@Api(tags = "资讯-个人中心")
@SuppressWarnings(value = "unchecked")
public class ArticleOwnerController extends BaseController {
    @Autowired
    private ArticleFrontEndManager articleManager;

    /**
     * 查询文章列表
     */
    @PostMapping("/listPage")
    @ApiOperation("个人中心-文章分页列表")
    @Repeat
    public PageResult<ArticleDTO> ownerListPage(@Validated @RequestBody ArticleOwnerListReq req) {
        IPage<ArticleDTO> page = articleManager.ownerListPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 查询收到的点赞
     */
    @PostMapping("/getLikesListPage")
    @ApiOperation("个人中心-收到的点赞分页列表")
    @Repeat
    public PageResult<ArticleGetLikesDTO> getLikeListPage(@Validated @RequestBody GetLikesListReq req) {
        IPage<ArticleGetLikesDTO> page = articleManager.getLikeListPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

}
